import { AnimationClip, AnimationComponent } from 'cc'
import { State } from '../../Base/AnimationState'
import { StateMachine } from '../../Base/StateMachine'
export const enum WOODEN_SKULL_STATE {
  IDLE_TOP = 'idle_top', //待机-上
  IDLE_LEFT = 'idle_left', //待机-左
  IDLE_RIGHT = 'idle_right', //待机-右
  IDLE_BOTTOM = 'idle_bottom', //待机-下
  ATTACK_TOP = 'attack_top', //攻击-上
  ATTACK_LEFT = 'attack_left', //攻击-左
  ATTACK_RIGHT = 'attack_right', //攻击-右
  ATTACK_BOTTOM = 'attack_bottom', //攻击-下
  DEATH_TOP = 'death_top', //死亡-上
  DEATH_LEFT = 'death_left', //死亡-左
  DEATH_RIGHT = 'death_right', //死亡-右
  DEATH_BOTTOM = 'death_bottom', //死亡-下
}
export class WoodenSkullStateMachine extends StateMachine<WOODEN_SKULL_STATE> {
  constructor(private _animationComponent: AnimationComponent) {
    super()
    this.initStateMap()
  }
  //初始化状态集合
  initStateMap() {
    const { Loop } = AnimationClip.WrapMode
    const speed = 1 / 8
    const acp = this._animationComponent
    const idleBaseUrl = 'texture/woodenskeleton/idle'
    const attackBaseUrl = 'texture/woodenskeleton/attack'
    const deathBaseUrl = 'texture/woodenskeleton/death'
    //待机
    this.addState(WOODEN_SKULL_STATE.IDLE_TOP, new State(acp, `${idleBaseUrl}/top/idle`, speed, Loop))
    this.addState(WOODEN_SKULL_STATE.IDLE_LEFT, new State(acp, `${idleBaseUrl}/left/idle`, speed, Loop))
    this.addState(WOODEN_SKULL_STATE.IDLE_RIGHT, new State(acp, `${idleBaseUrl}/right/idle`, speed, Loop))
    this.addState(WOODEN_SKULL_STATE.IDLE_BOTTOM, new State(acp, `${idleBaseUrl}/bottom/idle`, speed, Loop))

    //攻击
    this.addState(WOODEN_SKULL_STATE.ATTACK_TOP, new State(acp, `${attackBaseUrl}/top/attack`, speed))
    this.addState(WOODEN_SKULL_STATE.ATTACK_LEFT, new State(acp, `${attackBaseUrl}/left/attack`, speed))
    this.addState(WOODEN_SKULL_STATE.ATTACK_RIGHT, new State(acp, `${attackBaseUrl}/right/attack`, speed))
    this.addState(WOODEN_SKULL_STATE.ATTACK_BOTTOM, new State(acp, `${attackBaseUrl}/bottom/attack`, speed))

    //死亡
    this.addState(WOODEN_SKULL_STATE.DEATH_TOP, new State(acp, `${deathBaseUrl}/top/death`, speed))
    this.addState(WOODEN_SKULL_STATE.DEATH_LEFT, new State(acp, `${deathBaseUrl}/left/death`, speed))
    this.addState(WOODEN_SKULL_STATE.DEATH_RIGHT, new State(acp, `${deathBaseUrl}/right/death`, speed))
    this.addState(WOODEN_SKULL_STATE.DEATH_BOTTOM, new State(acp, `${deathBaseUrl}/bottom/death`, speed))
  }
}
